//托运方公司名称
$(function () {
    $("#company").autocomplete({
                                   source: function (request, response) {
                                       $.ajax({
                                                  url: "contacter-findListByName.do",
                                                  dataType: "json",
                                                  type: "post",
                                                  data: {name: request.term},
                                                  success: function (data) {
                                                      response(
                                                          $.map(data.contacters, function (item) {
                                                              return {
                                                                  id: item.id,
                                                                  username: item.name,
                                                                  phone: item.phone,
                                                                  label: item.name + " - "
                                                                         + item.company,
                                                                  value: item.company,
                                                                  address: item.address
                                                              };
                                                          }));
                                                  }
                                              });
                                   }, minLength: 0,
                                   search: function (event, ui) {
                                       //return false;
                                   },
                                   select: function (event, ui) {
                                       $("#company").val(ui.item.value);
                                       $("#phone").val(ui.item.phone);
                                       $("#name").val(ui.item.username);
                                       $("#address").val(ui.item.address);
                                       $("#shipId").val(ui.item.id);
                                   }
                               });
});
// 初始化表单
/*$(function() {
 var option = { success : function showResponse(responseText, statusText,
 xhr, $form) {
 alert($.parseJSON(responseText.msg).msg);
 //		if ($.parseJSON(responseText.msg).state == 1) {
 //			location.href = "business-businessList.do";//修改业务保存成功后返回业务管理页面
 //			location.href = "business-update.do";
 //		}
 } };
 $("#businessForm").ajaxForm(option);
 });*/
/**
 * 检查表单是否有数据
 *
 * @returns {Boolean}
 */
function checkForm(bizState) {
    var businessInput = $("#businessInput").val();
    if (bizState) {
        // 设定不同的业务状态
        $("#bizState").val(bizState);
    }
    var bizs = $("#busiType input[type=checkbox]");
    bizs = document.getElementsByName("busiType");
//	bizs = document.getElementsByTagName("input");
//	for(var i=0; i<bizs.length; i++){
//		bizs[i].type=="checkbox";
//	}
//	alert(bizs[0]);
    var bizSubmit = false;

    for (var i = 0; i < bizs.length; i++) {
        if (bizs[i].checked) {
            bizSubmit = true;
            if (bizs[i].id == 'book') {
                submit_booking();
            } else if (bizs[i].id == 'trail') {
                if (businessInput == null || businessInput == "") {
                    bizSubmit = confirmgoodesad();//在线下单完成按钮直接确认货物
                }
                submit_trail();
            } else if (bizs[i].id == 'declarate' || bizs[i].id == 'declarate1') {
                submit_decla();
            }
            if (!bizSubmit) {
                return false;
            }
        }
    }

//	$.each(bizs, function(i, n) {
//		if (n.checked) {
//			bizSubmit = true;
//			if (n.id == 'book') {
//				submit_booking();
//			} else if (n.id == 'trail') {
//				if(businessInput == null ||businessInput == "") {
//					bizSubmit = confirmgoodesad();//在线下单完成按钮直接确认货物
//				}
//				submit_trail();
//			} else if (n.id == 'declarate') {
////				bizSubmit = checkDeclaration();
//				submit_decla();
//			}
//			if(!bizSubmit){
//				return false;
//			}
//		}
//	});
    return bizSubmit;
}

function checkDeclaration() {
    /*
     * 第二步
     */
    var SELLER = $("#SELLER").val();//卖方
    var SELLER_ADDRESS = $("#SELLER_ADDRESS").val();//卖方地址
    var SELLER_PHONE = $("#SELLER_PHONE").val();//卖方电话
    var SELLER_FAX = $("#SELLER_FAX").val();//卖方传真
    var BUYER = $("#BUYER").val();//买方
    var FAHUO_COMPANY_NAME = $("#FAHUO_COMPANY_NAME").val();//发货单位
    var EXPORT_DATE = $("#EXPORT_DATE").val();//日期
    var GOODS_ADDR = $("#GOODS_ADDR").val();//境内货源地
    var ARRIVED_COUNTRY = $("#ARRIVED_COUNTRY").val();//运抵国
    var ARRIVED_PORT = $("#ARRIVED_PORT").val();//指运港
    var CARTON = $("#CARTON").val();//箱唛
    var GOODS_PACKAGE = $("#GOODS_PACKAGE").val();//包装种类
    var GOODS_COUNT = $("#GOODS_COUNT").val();//件数
    var GROSS_WEIGHT = $("#GROSS_WEIGHT").val();//毛重
    var NET_WEIGHT = $("#NET_WEIGHT").val();//净重
    /*
     * 第三步
     */
    var RECORD_ID = $("#RECORD_ID").val();//手册号
    var CONTRACT_NO = $("#CONTRACT_NO").val();//合同协议号
    var INVOICE_NO = $("#INVOICE_NO").val();//发票号
    var LC_TYPE = $("#LC_TYPE").val();//结汇方式
    var TRADE_MODE = $("#TRADE_MODE").val();//监管方式
    var LICENSE_NO = $("#LICENSE_NO").val();//许可证号
    var LEVYMODE = $("#LEVYMODE").val();//征免性质
    var DEAL_MODE = $("#DEAL_MODE").val();//成交方式

    if (!SELLER) {//第二步
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">卖方不能为空,请填写好卖方再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SELLER").focus();
            }, function () {
                $("#SELLER").focus();
            });
        return false;
    } else if (!SELLER_ADDRESS) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">卖方地址不能为空,请填写好卖方地址再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SELLER_ADDRESS").focus();
            }, function () {
                $("#SELLER_ADDRESS").focus();
            });
        return false;
    } else if (!SELLER_PHONE) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">卖方电话不能为空,请填写好卖方电话再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SELLER_PHONE").focus();
            }, function () {
                $("#SELLER_PHONE").focus();
            });
        return false;
    } else if (!SELLER_FAX) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">卖方传真不能为空,请填写好卖方传真再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SELLER_FAX").focus();
            }, function () {
                $("#SELLER_FAX").focus();
            });
        return false;
    } else if (!BUYER) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">买方不能为空,请填写好买方再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#BUYER").focus();
            }, function () {
                $("#BUYER").focus();
            });
        return false;
    } else if (!FAHUO_COMPANY_NAME) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">发货单位不能为空,请填写好发货单位再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#FAHUO_COMPANY_NAME").focus();
            }, function () {
                $("#FAHUO_COMPANY_NAME").focus();
            });
        return false;
    } else if (!EXPORT_DATE) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">日期不能为空,请填写好日期再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#EXPORT_DATE").focus();
            }, function () {
                $("#EXPORT_DATE").focus();
            });
        return false;
    } else if (!GOODS_ADDR) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">境内货源地不能为空,请填写好境内货源地再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_ADDR").focus();
            }, function () {
                $("#GOODS_ADDR").focus();
            });
        return false;
    } else if (!ARRIVED_COUNTRY) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">运抵国不能为空,请填写好运抵国再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#ARRIVED_COUNTRY").focus();
            }, function () {
                $("#ARRIVED_COUNTRY").focus();
            });
        return false;
    } else if (!ARRIVED_PORT) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">指运港不能为空,请填写好指运港再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#ARRIVED_PORT").focus();
            }, function () {
                $("#ARRIVED_PORT").focus();
            });
        return false;
    } else if (!CARTON) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">箱唛不能为空,请填写好箱唛再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CARTON").focus();
            }, function () {
                $("#CARTON").focus();
            });
        return false;
    } else if (!GOODS_PACKAGE) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">包装种类不能为空,请填写好包装种类再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_PACKAGE").focus();
            }, function () {
                $("#GOODS_PACKAGE").focus();
            });
        return false;
    } else if (!GOODS_COUNT) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">件数不能为空,请填写好件数再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_COUNT").focus();
            }, function () {
                $("#GOODS_COUNT").focus();
            });
        return false;
    } else if (!GROSS_WEIGHT) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">毛重不能为空,请填写好毛重再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GROSS_WEIGHT").focus();
            }, function () {
                $("#GROSS_WEIGHT").focus();
            });
        return false;
    } else if (!NET_WEIGHT) {
        declarationGotoTab(1);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">净重不能为空,请填写好净重再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#NET_WEIGHT").focus();
            }, function () {
                $("#NET_WEIGHT").focus();
            });
        return false;
    } else if (!RECORD_ID) {//第三步
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">手册号不能为空,请填写好手册号再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#RECORD_ID").focus();
            }, function () {
                $("#RECORD_ID").focus();
            });
        return false;
    } else if (!CONTRACT_NO) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">合同协议号不能为空,请填写好合同协议号再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CONTRACT_NO").focus();
            }, function () {
                $("#CONTRACT_NO").focus();
            });
        return false;
    } else if (!INVOICE_NO) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">发票号不能为空,请填写好发票号再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#INVOICE_NO").focus();
            }, function () {
                $("#INVOICE_NO").focus();
            });
        return false;
    } else if (!LC_TYPE) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">结汇方式不能为空,请填写好结汇方式再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LC_TYPE").focus();
            }, function () {
                $("#LC_TYPE").focus();
            });
        return false;
    } else if (!TRADE_MODE) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">监管方式不能为空,请填写好监管方式再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#TRADE_MODE").focus();
            }, function () {
                $("#TRADE_MODE").focus();
            });
        return false;
    } else if (!LICENSE_NO) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">许可证号不能为空,请填写好许可证号再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LICENSE_NO").focus();
            }, function () {
                $("#LICENSE_NO").focus();
            });
        return false;
    } else if (!LEVYMODE) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">征免性质不能为空,请填写好征免性质再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LEVYMODE").focus();
            }, function () {
                $("#LEVYMODE").focus();
            });
        return false;
    } else if (!DEAL_MODE) {
        declarationGotoTab(2);
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">成交方式不能为空,请填写好成交方式再确定货物！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#DEAL_MODE").focus();
            }, function () {
                $("#DEAL_MODE").focus();
            });
        return false;
    }
    return true;
}

function declarationGotoTab(index) {
    var $li = $('#tab li');
    var $ul = $('#content ul');
    //var $t = $li.parent().find(".current").index()+1;
    $li.removeClass();
    $li.eq(index).addClass('current');
    $ul.css('display', 'none');
    $ul.eq(index).css('display', 'block');
}

//提交报关单
function submit_decla() {
    //报关商品
//	var decla_goods_trs = $("#goodsListTB tr");
    var decla_goods_trs = $("#goods_list table").contents().find("tr");
    if (decla_goods_trs.length > 1) {
        var temp_tr0_tds = $(decla_goods_trs[0]).find("th");
        var index = 0;
        var temp_goodsInput = "";
        for (var i = 1; i < decla_goods_trs.length; i++) {
            var dGoodsTds = $(decla_goods_trs[i]).find("td");
            index = dGoodsTds[0].innerText - 1;
            for (var j = 0; j < temp_tr0_tds.length; j++) {
                if ($(temp_tr0_tds[j]).attr("lang") && $(temp_tr0_tds[j]).attr("lang") != "INDEX") {
//					var dGoodInputs = dGoodsTds[j].find("input");
//					var dGoodInputs = dGoodsTds[j];
//					if(dGoodInputs.length!=0){
                    temp_goodsInput = temp_goodsInput
                                      + "<input type='hidden' name='commodities[" + index
                                      + "]."
                                      + $(temp_tr0_tds[j]).attr("lang")
                                      + "' value=\"" + $(dGoodsTds[j]).text() + "\" \/>";
//					}else{
//						temp_goodsInput = temp_goodsInput
//						+ "<input type='hidden' name='declare.commodities[" + index + "]."
//						+ $(temp_tr0_tds[j]).attr("lang")
//						+ "' value=\"" + $(dGoodsTds[j]).text()+"\" \/>";
//					}
                }
            }
//			index++;
        }
        $("#input_declare_goods").html("");
        $("#input_declare_goods").html(temp_goodsInput);
    }
    //报关随附单
//	var decla_suifu_trs = $("#suifudanListTB tr");
//	if(decla_suifu_trs.length > 1){
//		var temp_tr0_tds = $(decla_suifu_trs[0]).find("td");
//		var index = 0;
//		var temp_goodsInput = "";
//		for(var i=1; i<decla_suifu_trs.length; i++){
//			var dGoodsTds = $(decla_suifu_trs[i]).find("td");
//			for(var j=0; j<temp_tr0_tds.length; j++){
//				if($(temp_tr0_tds[j]).attr("lang") &&
// $(temp_tr0_tds[j]).attr("lang")!="suifudan_num"){ temp_goodsInput = temp_goodsInput  + "<input
// type='hidden' name='declare.suiFuDans["  + index +"]." + $(temp_tr0_tds[j]).attr("lang")  + "'
// value=\"" + $(dGoodsTds[j]).text()+"\" \/>"; } } index++; }
// $("#input_declare_suifudans").html(""); $("#input_declare_suifudans").html(temp_goodsInput); }
}

/**
 * 提交表单
 */
function submit_trail() {
    // 拼装拖车货物列表
    var trial_trs = $("#tril_goodsList tr");
    if (trial_trs.length > 1) {
        var inputs = "";
        var columns = null;
        $
            .each(trial_trs, function (i, n) {
                try {
                    if (i == 0) {
                        columns = $(n).find("td");
                    } else {
                        var values = $(n).find("td");
                        $
                            .each(columns, function (k, m) {
                                var column = $(m).attr("lang");
                                if (column != undefined && column != null) {
                                    var value = $(values[k]).text();
                                    if (value != undefined && value != null) {
                                        if ($(m).attr("lang") == "zhDate") {
                                            value = $(values[10]).text();
                                        }
                                        value = $.trim(value);
                                    } else {
                                        value = "";
                                    }
                                    inputs +=
                                        "<input type='hidden' name='trial.gdes[" + (i - 1) + "]."
                                        + column
                                            .replace(/_/g, ".") + "' value=\"" + value + "\" />";

                                    if ($(m).attr("lang") == "ctNumTypeSo") {
                                        var indexSo = value.indexOf("+");
                                        var so = value.substring(indexSo + 1, value.length);
                                        var valueTemp = value.substring(0, indexSo);
                                        var containersTemp = valueTemp.split(",");
                                        var containers = "";
                                        for (var p = 0; p < containersTemp.length; p++) {
                                            containers =
                                                containers + containersTemp[p] + "+" + so + ",";
                                        }
                                        containers =
                                            containers.substring(0, containers.length - 1).split(
                                                ",");

                                        var ids = $(values[values.length - 5]) //length - 5获取柜id字段
                                            .text().substring(0, indexSo);

                                        if (ids != undefined && ids != null) {
                                            // 如果有id则解析
                                            ids = ids.split(",");
                                        } else {
                                            ids = "";
                                        }
                                        $
                                            .each(containers, function (j, t) {

                                                var index1 = t.indexOf("-");
//															var index1 = "";
                                                if (index1 == "-1") {
                                                    index1 = t.indexOf("x");
                                                }
                                                var index2 = t.indexOf("'");
                                                var index3 = t.indexOf("+");
                                                if ($.trim(ids)) {
                                                    inputs +=
                                                        "<input type='hidden' name='trial.gdes["
                                                        + (i - 1) + "].containers[" + j
                                                        + "].id' value=" + ids[j] + " />";
                                                } else {
                                                    inputs +=
                                                        "<input type='hidden' name='trial.gdes["
                                                        + (i - 1) + "].containers[" + j
                                                        + "].id' value=" + t
                                                            .substr(0, index1) + " />";
                                                }
                                                inputs +=
                                                    "<input type='hidden' name='trial.gdes[" + (i
                                                                                                - 1)
                                                    + "].containers[" + j + "].ct_size' value=" + t
                                                        .substring(index1 + 1, index2) + " />";
                                                inputs +=
                                                    "<input type='hidden' name='trial.gdes[" + (i
                                                                                                - 1)
                                                    + "].containers[" + j + "].ct_type' value=" + t
                                                        .substring(index2 + 1, index3) + " />";
                                                inputs +=
                                                    "<input type='hidden' name='trial.gdes[" + (i
                                                                                                - 1)
                                                    + "].containers[" + j + "].so' value=" +
                                                    t.substring(index3 + 1, t.length) + " />";
                                            });
                                    }

//											if ($(m).attr("lang") == "ctNumType") {
//												var containers = value
//														.split(",");
//												var ids = $(values[values.length - 1])
//														.text();
//												if (ids != undefined && ids != null) {
//													// 如果有id则解析
//													ids = ids.split(",");
//												} else {
//													ids = "";
//												}
//												$
//														.each(containers, function(
//																j, t) {
//
//															var index1 = t
//																	.indexOf("-");
//															var index2 = t
//																	.indexOf("'");
//															if ($.trim(ids)) {
//																inputs += "<input type='hidden'
// name='trial.gdes[" + (i - 1) + "].containers[" + j + "].id' value=" + ids[j] + " />"; } else {
// inputs += "<input type='hidden' name='trial.gdes[" + (i - 1) + "].containers[" + j + "].id'
// value=" + t .substr(0, index1) + " />"; } inputs += "<input type='hidden' name='trial.gdes[" +
// (i - 1) + "].containers[" + j + "].ct_size' value=" + t .substring(index1 + 1, index2) + " />";
// inputs += "<input type='hidden' name='trial.gdes[" + (i - 1) + "].containers[" + j + "].ct_type'
// value=" + t .substring(index2 + 1, t.length) + " />"; }); }
                                }
                            });
                    }
                } catch (e) {
                    alert(e);
                }
            });
        $("#new_tril_goodsList").html("");
        $("#new_tril_goodsList").append(inputs);
    }
}

//检查用户同时操作：订舱，拖车，报关中的多少个业务
function checkBusiNum() {
    //var busiType=[F,C,D,all];订舱，拖车，报关，全部
    var busiOrder = 0;//选择了订舱，拖车，报关中的数目，用于判断跳转页面
    var str = '';//用于判断当单个业务时选择操作的是第几个业务
//	var bizs = $("#busiType input[type=checkbox]");
    var bizs = document.getElementsByName("busiType");
    for (var i = 0; i < bizs.length; i++) {
        if (bizs[i].checked) {
            busiOrder++;
            str += 'a';
        } else {
            str += 'b';
        }
    }
//	$.each(bizs,function(i,n){
//		if(n.checked){
//			busiOrder++;
//			str+='a';
//		}else{
//			str+='b';
//		}
//	});
    var no = str.indexOf('a');
    //设置选择下单类型
//	if(busiOrder>1){
//		$("#singleTypeInput").val('all');
//	}else if(no==0){
//		$("#singleTypeInput").val('F');
//	}else if(no==1){
//		$("#singleTypeInput").val('C');
//	}else if(no==2){
//		$("#singleTypeInput").val('D');
//	}
    if (busiOrder > 1) {
        $("#singleTypeInput").val('all');
    } else if (no == 0) {
        $("#singleTypeInput").val('C');
    } else if (no == 1 || no == 2 || no == 3) {
        $("#singleTypeInput").val('D');
    }
    //方便寄送资料提醒
    if (str.lastIndexOf("a") == 2 && busiOrder > 1) {
        $("#singleTypeInput").val('withD');
    }
}
//用于报关提交时设置的寄送资料提醒功能
function declareRemind(declareId, singleTypeInput) {
    var id = declareId;
    jw.confirm("提交订单成功，是否需要快递资料,请填写快递资料提醒!", function () {
                   jw.dialog({
                                 iframe: "sendremind-sendAdd.do?ID=" + id + "&pageType=" + singleTypeInput,
                                 width: 500,
                                 height: 100,
                                 over: false
                             });
               },
               function () {
                   if (singleTypeInput == 'withD') {
                       location.href = "business-businessList.do";
                   } else if (singleTypeInput == "D") {
                       location.href = "declaration-main.do";
                   }
               });
}

//初始化表单
$(function () {
    //ajax表单提交配置,success:提交成功后执行的方法
    var option = {
        contentType: "application/x-www-form-urlencoded; charset=utf-8",
        success: function showResponse(responseText, statusText,
                                       xhr, $form) {
            checkBusiNum();
            //业务操作结果
            //后台用html返回，现转换成json格式
            var rsJson = responseText;
            if (!rsJson.result) {
                alert(rsJson.msg + " :" + rsJson.data);
                $("#saveBtn").attr("disabled", false);
                $("#submitBtn").attr("disabled", false);
                return;
            }
            var bizState = $("#bizState").val();
            var singleTypeInput = $("#singleTypeInput").val();
            var id = rsJson.data.id;//拖车id 或者报关id
            var businessId = rsJson.data.businessId;
            var dstate = $("#stateVal").val();
//		有报关单提交成功时要提醒客户是否进行寄送资料提醒
            if (bizState == 1 && (singleTypeInput == "withD" || singleTypeInput == "D")
                && rsJson.result) {
                declareRemind(id, singleTypeInput);
            } else {
                var msg = rsJson.msg;
                if (!rsJson.result) {
                    $(":button").removeAttr("disabled");
                }
                if (rsJson.result && rsJson.data.isSubmit == 1) {
                    if (singleTypeInput != undefined) {
                        if (singleTypeInput == 'all' || singleTypeInput == "withD") {
                            location.href = "business-businessList.do";
                        } else if (singleTypeInput == 'C') {
                            location.href = "trail-main.do";
                        } else if (singleTypeInput == "F") {
                            location.href = "booking-main.do";
                        } else if (singleTypeInput == "D") {
                            if (dstate == "DS03") {
                                location.href = "declaration-setAccount.do?declaration_ids=" + id;
                            } else {
                                var params = (id + "").replace(/,/gi, '&declaration_ids=');
                                window.location.href =
                                    "declaration-confirmPay?declaration_id=" + params;
                            }

                        }
                    } else {
                        location.href = "business-businessList.do";//修改业务保存成功后返回业务管理页面
                    }
                } else {
                    if (rsJson.result) {
                        if (singleTypeInput != undefined) {
                            if (singleTypeInput == 'all' || singleTypeInput == "withD") {
                                location.href = "business-businessList.do";
                            } else if (singleTypeInput == 'C') {
//								location.href = "trail-main.do";
                                location.href =
                                    "business-updateSingle.do?id=" + id
                                    + "&singleType=C&businessId=" + businessId;
                            } else if (singleTypeInput == "F") {
                                location.href = "booking-main.do";
                            } else if (singleTypeInput == "D") {
                                location.href =
                                    "business-updateSingle.do?id=" + id
                                    + "&singleType=D&businessId=" + businessId;
                            }
                        } else {
                            location.href = "business-businessList.do";//修改业务保存成功后返回业务管理页面
                        }
                    }
                }

            }
        }
    };
    $("#businessForm").ajaxForm(option);
});

var tabs = null;

//	busi('trail','business-trail.do','拖车');

//展示tab
//z(id, url, title,ajaxOption) {
//	if (tabs == null) {
//		tabs = $("#tabs").tabs({ cache : true });
//	}
//	var index=$("#liList li").size();
//	var ctime=new Date();
//	var tdate=ctime.getTime();
//	url=url+(url.indexOf("?")==-1?"?":"&");
//	if(ajaxOption){
//		tabs.tabs({ajaxOptions: ajaxOption });
//	}else{
//		tabs.tabs({ajaxOptions:null});
//	}
//	tabs.tabs("add", url+"tdate="+tdate, title, index);
//	tabs.tabs("select", index);
//}

function returnBack() {
    //TODO 报关报检业务管理 -页面返回
    var singleTypeInput = $("#singleTypeInput").val();
    var declareState = $("#declareStateInput").val();
    if (singleTypeInput == "C") {//拖车
        location.href = "trail-main.do";
    } else if (singleTypeInput == "F") {//订舱
        location.href = "booking-main.do";
    } else if (singleTypeInput == "D") {//报关
//		location.href = "declaration-main.do";
        var com_type = $("#com_type").val();
        if (com_type == "CL") {
            location.href = "business-main.do";
        } else if (com_type == "CC") {
            if (declareState == "DS01") {
                location.href = "declaration-listForSupToValidate.do?declaraState=DS01";
            } else if (declareState == "DS04" || declareState == "DS02") {
                location.href = "declaration-listForSupToValidate.do?declaraState=DS02";
            } else if (declareState == "DS03") {
                location.href = "declaration-listForSupToValidate.do?declaraState=DS03";
            }
//			location.href = "declaration-main.do";
        }

    } else {//业务管理页面
        location.href = "business-businessList.do";
    }
}
/**
 * 为运营商页面查看详细的页面的返回跳转页面
 */
function returnBackForSup() {
    var singleTypeInput = $("#singleTypeInput").val();
    if (singleTypeInput == "C") {//拖车
        location.href = "trail-listForSupToValidate.do";
    } else if (singleTypeInput == "F") {//订舱
        location.href = "booking-listForSupToValidate.do";
    } else if (singleTypeInput == "D") {//报关
        location.href = "declaration-listForSupToValidate.do";
    } else {//业务管理页面
//		location.href = "business-businessList.do";
    }
}

/**
 * 保存时提示没有选择的柜
 */
function noChoiceContainers() {
    //确认总柜量
    var containers = new Array();
    var containerTypeSpan = $("#containers li:first span");
    var index = 1;
    $.each(containerTypeSpan, function (i, n) {
        var inputs = $(n).find("input");
        var num = new Number($(inputs[0]).val());
        if (num != 0) {
            var size = $(inputs[1]).val();
            var type = $(inputs[2]).val();
            for (var i = 0; i < num; i++) {
                var container = {
                    id: index, size: size, type: type,
                    index: index
                };
                containers.push(container);
                index++;
            }
        }
    });
    var containersList = new Array();
    $.each(containers, function (i, n) {
        containersList.push(n.id + "号柜-" + n.size + "'" + n.type);
    });
    //统计商品列表柜量总数
    var sizeType = new Array();
    var number = $("#tril_goodsList").find("tr").length;
    if (number <= 1) {
        return;
    }
    var strTemp = "";
    for (; number > 1; number--) {
        strTemp += $("#tril_goodsList").find("tr").eq(number - 1).find("td").eq(8).text();
        strTemp += ",";
    }
    strTemp = strTemp.substring(0, strTemp.length - 1);
    sizeType = strTemp.split(",");
    //去重
    var tempArray = [];
    var tempObj = {};
    for (var i = 0; i < sizeType.length; i++) {
        if (!tempObj[sizeType[i]]) {
            tempArray.push(sizeType[i]);
            tempObj[sizeType[i]] = 1;
        }
    }
    //获得没有选择的柜量柜型
    var tempList = new Array();
    for (var i = 0; i < containersList.length; i++) {
        var flag = false;
        for (var j = 0; j < sizeType.length; j++) {
            if (containersList[i] == sizeType[j]) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            tempList.push(containersList[i]);
        }
    }
    var tempContainers = "";
    $.each(tempList, function (i, n) {
        tempContainers += n + ",";
    });
    if (tempContainers != "") {
        tempContainers = tempContainers.substring(0, tempContainers.length - 1);
    }
    return tempContainers;

}

// 提交新增数据表单
function check(bizState) {
//	if(bizState == 0) {
//		confirmgoodesad();
//	}
    refreshGoodsTotal();//统计计价数量、净重、毛重等
    var companyName = $("#company").attr("value");
    //获取订舱页面订舱业务代理人的值
//	var book_boat = $(".bizMsg").contents().find("#book_boat_id").addClass("on").val();
    var book_boat = $("#book_boat").val();
    var book_boat_id = $("#book_boat_id").val();
    //获取订舱大船公司,起运港，目的港的值
    var book_ship_id = $("#book_ship_id").val();
    var book_ship = $("#book_ship").val();
    var stPort_book = $("#stPort_book").val();
    var stPort_book_id = $("#stPort_book_id").val();
    var arPort_book = $("#arPort_book").val();
    var arPort_book_id = $("#arPort_book_id").val();
    //获取订舱货物列表的行数
    var book_goods_size = $("#goodsList tr").size();
    //获取拖车页面拖车业务代理人的值
    var trial_sup = $(".page_font").contents().find("#trial_sup_id").addClass("on").val();
    //获取拖车柜量信息值
    var ct_num = $("#ct_num").val();
    //获取拖车页面货物列表的行数
    var trial_goods_size = $(".page_font").contents().find("#tril_goodsList tr").addClass(
        "on").size();
    //获取报关页面货物列表的行数
    //var declaration_goods_size = $(".page_font").contents().find("#goodsListTB
    // tr").addClass("on").size();
    var declaration_goods_size = $("#goods_list table").contents().find("tr").size();
    var bookIsChecked = $("#book").attr("checked");
    var trailIsChecked = $("#trail").attr("checked");
    var declarationIsChecked = $("#declarate").attr("checked");
    var msg = "";
//	if (bizState == 0) {
//		msg = "您是否要保存订单？";
//	} else {
//		msg = "请确定资料填写无误，提交后将不能修改?";
//	}
    if (companyName) {
        if (bookIsChecked) {
            if (book_boat == "" || book_boat_id == "") {
                alert("请填写订舱业务代理人!");
                $("#tabs").tabs("select", 0);
                $("#book_boat_id").focus();
                return;
            } else if (book_goods_size < 2) {
                alert("请填写货物信息,并确认货物!");
                $("#goodsName").focus();
                return;
//			} else if(book_ship_id=="" || book_ship=="") {
//				alert("请填写大船公司 !");
//				$("#book_ship_id").focus();
//				return;
            } else if (stPort_book == "" || stPort_book_id == "") {
                alert("请填写起始港!");
                $("#stPort_book").focus();
                return;
            } else if (arPort_book == "" || arPort_book_id == "") {
                alert("请填写目的港!");
                $("#arPort_book").focus();
                return;
            }
        }
        if (trailIsChecked) {//拖车保存、提交时验证
            if (trial_sup == "") {
                alert("请填写拖车业务代理人!");
                $("#tabs").tabs("select", 1);
                $("#trial_sup_id").focus();
                return;
            } else if (trial_goods_size < 2) {//先检测拖车货物列表是否值
                if (ct_num == null || ct_num == "") {
                    alert("请填写柜量信息，并确认柜量!");
                    $("#ct_num").focus();
                    return;
                }
            } else if (trial_goods_size < 2) {
                alert("柜型不能为空,请选择好柜型确定货物后再保存提交!");
                return;
            }
        }

        var EXPORT_PORT = $("#EXPORT_PORT").val();//出口口岸
        var DECLARATION_PORT = $("#DECLARATION_PORT").val();//申报口岸
        var declaration_sup_id = $("#declaration_sup_id").val();//报关行
        if (EXPORT_PORT == "") {
            jw.confirm(
                '<div><p style="font-style: normal;font-size: 16px;color:red;">出口口岸不能为空,请填写出口口岸再保存！</p></div>',
                function () {
                    $(this).dialog('destroy');
                    $("#EXPORT_PORT").focus();
                }, function () {
                    $("#EXPORT_PORT").focus();
                });
            return true;
        } else if (DECLARATION_PORT == "") {
            jw.confirm(
                '<div><p style="font-style: normal;font-size: 16px;color:red;">申报口岸不能为空,请填写申报口岸再保存！</p></div>',
                function () {
                    $(this).dialog('destroy');
                    $("#DECLARATION_PORT").focus();
                }, function () {
                    $("#DECLARATION_PORT").focus();
                });
            return true;
        } else if (declaration_sup_id == "") {
            jw.confirm(
                '<div><p style="font-style: normal;font-size: 16px;color:red;">报关行不能为空,请填写报关行再保存！</p></div>',
                function () {
                    $(this).dialog('destroy');
                    $("#declaration_sup_id").focus();
                }, function () {
                    $("#declaration_sup_id").focus();
                });
            return true;
        }

//		if(declarationIsChecked) {//报关保存、提交验证
//			if(testRequired()) {
//				return;
//			}
//		}
//		if(declarationIsChecked) {
//			if(declaration_goods_size<2) {
//				alert("商品名称和商品编号不能为空,请填写并确认后再保存提交!");
//				return;
//			}
//		}
//		if(testRequired()) {
//			return;
//		} else {
//			if (bizState == 0) {
//				msg = "您是否要保存订单？";
////				msg = "您是否确认所有装运信息？";
//			} else {
//				msg = "请确定资料填写无误，提交后将不能修改?";
//			}
//			var	msgHTML = '<div><p style="font-style: normal;font-size: 16px;color:red;">' +
// msg + '</p></div>'; var bizSubmit = checkForm(bizState); if (bizSubmit) { jw.confirm(msgHTML,
// function() { $(":button").attr("disabled","disabled"); var ctime = new Date(); var tdate =
// ctime.getTime(); $("#businessForm") .attr("action", "business-add.do?tdate=" + tdate);
// $("#businessForm").submit(); $("#saveBtn").attr("disabled",true);
// $("#submitBtn").attr("disabled",true); }, function() {  }, 'Confirm Delete'); } }
        if (bizState == 0) {
            msg = "您是否要保存订单？";
        } else {
            msg = "请确定资料填写无误，提交后将不能修改?";
        }
        var msgHTML = '<div><p style="font-style: normal;font-size: 16px;color:red;">' + msg
                      + '</p></div>';

        jw.confirm(msgHTML, function () {
            var bizSubmit = checkForm(bizState);
            if (bizSubmit) {
                $(":button").attr("disabled", "disabled");
                var ctime = new Date();
                var tdate = ctime.getTime();
                $("#businessForm")
                    .attr("action", "business-add.do?bizType=D&tdate=" + tdate);
                $("#businessForm").submit();

                $("#saveBtn").attr("disabled", true);
                $("#submitBtn").attr("disabled", true);
            }
        }, function () {

        }, 'Confirm Delete');
    } else {
        alert("请填写公司名称！");
    }
}

//跳转到第二步
function jumpToStepSecond() {
    var $li = $('#tab li');
    var $ul = $('#content ul');
    $li.removeClass();
    $li.eq(1).addClass('current');
    $ul.css('display', 'none');
    $ul.eq(1).css('display', 'block');
}

//检验第二步必填项
function testRequired() {
    var SELLER = $("#SELLER").val();//卖方
    var BUYER = $("#BUYER").val();//买方
    var GOODS_ADDR_SHOW = $("#GOODS_ADDR_SHOW").val();//境内货源地
    var FAHUO_COMPANY_NAME = $("#FAHUO_COMPANY_NAME").val();//发货单位
    var CONTRACT_DATE = $("#CONTRACT_DATE").val();//日期
    var CONTRACT_NO = $("#CONTRACT_NO").val();//合同协议号
    var INVOICE_NO = $("#INVOICE_NO").val();//发票号
    var LEVYMODE_SHOW = $("#LEVYMODE_SHOW").val();//征免性质
    var GOODS_PACKAGE = $("#GOODS_PACKAGE").val();//包装种类
    var TRADE_MODE_SHOW = $("#TRADE_MODE_SHOW").val();//监管方式
    var TRANSPORT_MODE = $("#TRANSPORT_MODE").val();//运输方式
    var LC_TYPE_SHOW = $("#LC_TYPE_SHOW").val();//结汇方式
    var DEAL_MODE_SHOW = $("#DEAL_MODE_SHOW").val();//成交方式
    var REMARK = $("#REMARK").val();//备注
    var SO = $("#SO").val();//SO号
    var CONTAINER_NO = $("#CONTAINER_NO").val();//柜号
    var containerInfoId = $("#containerInfoId").val();//分柜资料ID
    var EXPORT_PORT = $("#EXPORT_PORT").val();//出口口岸
    var DECLARATION_PORT = $("#DECLARATION_PORT").val();//申报口岸
    var declaration_sup_id = $("#declaration_sup_id").val();//报关行
    var TRADING_COUNTRY = $("#TRADING_COUNTRY").val();//贸易国
    var SPECIAL_RELATIONSHIP_CONFIRM = $("#SPECIAL_RELATIONSHIP_CONFIRM").val();//特殊关系确认
    var PRICE_IMPACT_CONFIRM = $("#PRICE_IMPACT_CONFIRM").val();//价格影响确认
    var PAYMENT_ROYALTIES_CONFIRM = $("#PAYMENT_ROYALTIES_CONFIRM").val();//支付特许权使用费确认
    if (EXPORT_PORT == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">出口口岸不能为空,请填写出口口岸再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#EXPORT_PORT").focus();
            }, function () {
                $("#EXPORT_PORT").focus();
            });
        return true;
    } else if (DECLARATION_PORT == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">申报口岸不能为空,请填写申报口岸再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#DECLARATION_PORT").focus();
            }, function () {
                $("#DECLARATION_PORT").focus();
            });
        return true;
    } else if (declaration_sup_id == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">报关行不能为空,请填写报关行再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#declaration_sup_id").focus();
            }, function () {
                $("#declaration_sup_id").focus();
            });
        return true;
    } else if (SELLER == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">卖方不能为空,请填写卖方再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SELLER").focus();
            }, function () {
                $("#SELLER").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (BUYER == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">买方不能为空,请填写买方再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#BUYER").focus();
            }, function () {
                $("#BUYER").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (GOODS_ADDR_SHOW == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">境内货源地不能为空,请填写境内货源地再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_ADDR_SHOW").focus();
            }, function () {
                $("#GOODS_ADDR_SHOW").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (FAHUO_COMPANY_NAME == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">发货单位不能为空,请填写发货单位再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#FAHUO_COMPANY_NAME").focus();
            }, function () {
                $("#FAHUO_COMPANY_NAME").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (CONTRACT_DATE == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">日期不能为空,请填写日期再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CONTRACT_DATE").focus();
            }, function () {
                $("#CONTRACT_DATE").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (CONTRACT_NO == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">合同协议号不能为空,请填写合同协议号再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#CONTRACT_NO").focus();
            }, function () {
                $("#CONTRACT_NO").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (INVOICE_NO == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">发票号不能为空,请填写发票号再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#INVOICE_NO").focus();
            }, function () {
                $("#INVOICE_NO").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (LEVYMODE_SHOW == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">征免性质不能为空,请填写征免性质再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LEVYMODE_SHOW").focus();
            }, function () {
                $("#LEVYMODE_SHOW").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (GOODS_PACKAGE == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">包装种类不能为空,请填写包装种类再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#GOODS_PACKAGE").focus();
            }, function () {
                $("#GOODS_PACKAGE").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (TRADE_MODE_SHOW == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">监管方式不能为空,请填写监管方式再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#TRADE_MODE_SHOW").focus();
            }, function () {
                $("#TRADE_MODE_SHOW").focus();
            });
    } else if (TRANSPORT_MODE == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">运输方式不能为空,请填写运输方式再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#TRANSPORT_MODE").focus();
            }, function () {
                $("#TRANSPORT_MODE").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (LC_TYPE_SHOW == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">结汇方式不能为空,请填写结汇方式再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#LC_TYPE_SHOW").focus();
            }, function () {
                $("#LC_TYPE_SHOW").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (DEAL_MODE_SHOW == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">成交方式不能为空,请填写成交方式再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#DEAL_MODE_SHOW").focus();
            }, function () {
                $("#DEAL_MODE_SHOW").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (TRADING_COUNTRY == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">贸易国(地区)不能为空,请填写再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#TRADING_COUNTRY").focus();
            }, function () {
                $("#TRADING_COUNTRY").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (SPECIAL_RELATIONSHIP_CONFIRM == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">特殊关系确认不能为空,请填写再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#SPECIAL_RELATIONSHIP_CONFIRM").focus();
            }, function () {
                $("#SPECIAL_RELATIONSHIP_CONFIRM").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (PRICE_IMPACT_CONFIRM == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">价格影响确认不能为空,请填写再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#PRICE_IMPACT_CONFIRM").focus();
            }, function () {
                $("#PRICE_IMPACT_CONFIRM").focus();
            });
        jumpToStepSecond();
        return true;
    } else if (PAYMENT_ROYALTIES_CONFIRM == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">支付特许权使用费确认不能为空,请填写再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#PAYMENT_ROYALTIES_CONFIRM").focus();
            }, function () {
                $("#PAYMENT_ROYALTIES_CONFIRM").focus();
            });
        jumpToStepSecond();
        return true;
    }
    else if (REMARK == "") {
        jw.confirm(
            '<div><p style="font-style: normal;font-size: 16px;color:red;">备注不能为空,请填写备注再保存！</p></div>',
            function () {
                $(this).dialog('destroy');
                $("#REMARK").focus();
            }, function () {
                $("#REMARK").focus();
            });
        jumpToStepSecond();
        return true;
    }
}

// 保存修改数据表单
function updateBiz() {
//	if(testRequired()) {
//		return;
//	} else {
    $("#sumit").attr("disabled", true);
    $("#tijiao").attr("disabled", true);
    $("#sumit1").attr("disabled", true);
    $("#tijiao1").attr("disabled", true);
    var disChoiceContainers = noChoiceContainers();
    if (disChoiceContainers == null || disChoiceContainers == "") {
        var bizSubmit = checkForm();
        if (bizSubmit) {
            jw.confirm("是否确定保存业务", function () {
                $("#businessForm").attr("action", "business-edit.do?tdate=" + timeNum());
                $("#businessForm").submit();
            }, function () {
                $("#sumit").attr("disabled", false);
                $("#tijiao").attr("disabled", false);
                $("#sumit1").attr("disabled", false);
                $("#tijiao1").attr("disabled", false);
                return;
            });
        }
    } else {
        var bizSubmit = checkForm();
        if (bizSubmit) {
            jw.confirm("您有如下柜：'" + disChoiceContainers + "'是否确定保存业务", function () {
                $("#businessForm").attr("action", "business-edit.do?tdate=" + timeNum());
                $("#businessForm").submit();
            }, function () {
                $("#sumit").attr("disabled", false);
                $("#tijiao").attr("disabled", false);
                $("#sumit1").attr("disabled", false);
                $("#tijiao1").attr("disabled", false);
                return;
            });
        }
    }
//	}
//		$("#businessForm")
//				.attr("action", "business-edit.do?tdate=" + timeNum());
//		$("#businessForm").submit();
}
//提交修改的数据表单
function summitBiz(businessId) {
    if (testRequired()) {
        return;
    } else {
        var disChoiceContainers = noChoiceContainers();
        if (disChoiceContainers == null || disChoiceContainers == "") {
            var bizSubmit = checkForm();
            if (bizSubmit) {
                jw.confirm("是否确定提交业务", function () {
                    $("#sumit").attr("disabled", true);
                    $("#tijiao").attr("disabled", true);
                    $("#sumit1").attr("disabled", true);
                    $("#tijiao1").attr("disabled", true);
                    $("#businessForm").attr(
                        "action",
                        "business-edit.do?summitBiz=Y&businessId=" + businessId
                        + "&tdate=" + timeNum());
                    $("#businessForm").submit();
                }, function () {
                    $("#sumit").attr("disabled", false);
                    $("#tijiao").attr("disabled", false);
                    $("#sumit1").attr("disabled", false);
                    $("#tijiao1").attr("disabled", false);
                    return;
                });
            }
        } else {
            var bizSubmit = checkForm();
            if (bizSubmit) {
                jw.confirm("您有如下柜：'" + disChoiceContainers + "'是否确定提交业务", function () {
                    $("#businessForm")
                        .attr("action",
                              "business-edit.do?summitBiz=Y&businessId=" + businessId + "&tdate="
                              + timeNum());
                    $("#businessForm").submit();
                }, function () {
                    return;
                });
            }
        }
    }
//		$("#businessForm").attr("action", "business-edit.do?tdate=" + timeNum());
//		$("#businessForm").submit();
//		if($('#book').attr('checked')){
//			var id=$('#bookId').val();
//			id='id='+id;
//			alert(id);
//			$.ajax({url : "booking-bizConfirm.do",
//				   dataType : "json",
//				   data : id,
//				   success: function(data){
//					   jw.alert($.parseJSON(data.msg).msg);
//				   }});
//		}

}

function checkedAll(obj, type) {
    var obj_id = $(obj).attr("id");
    var n = "";
    if (obj_id) {
        n = obj_id.split("_")[2];
    }
    if (!n || n == "") {
        n = "";
    } else {
        n = "_" + n;
    }
    $("#gd_ctNumType" + n).focus();
    $("#gd_ctNumType" + n).blur();
    //var selectAll = $("#selectall_checkbox"+n).is(':checked');
    var selectAll = type;
    var inputs = $("#gd_ctNumType" + n).autocomplete("widget").find("input");
    var value = "";
    if (selectAll == false) {
        for (var i = 0; i < inputs.length; i++) {
            $("#gd_ctNumType" + n).autocomplete("widget").find("input").eq(i).attr("checked",
                                                                                   false);
        }
        $("#gd_ctNumType" + n).val("");
        $(obj).parent().parent().find("span[id^='gd_ctNumType_show']").text("");
    } else {
        for (var i = 0; i < inputs.length; i++) {
            $("#gd_ctNumType" + n).autocomplete("widget").find("input").eq(i).attr("checked", true);
            value +=
                $("#gd_ctNumType" + n).autocomplete("widget").find("input").eq(i).parent("a").eq(
                    0).text();
            if (i != inputs.length - 1) {
                value += ",";
            }
        }
        $("#gd_ctNumType_show" + n).text(value);
        countSizeType($("#gd_ctNumType_show" + n), n, "");
        //$("#gd_ctNumType").val(value);
    }

}

//确认柜量
function showTrailInfo() {
    //var tabs_height=$('#tabs').height();
    if ($("#ct_num").val() == "") {
        alert("请填写柜量!");
        return false;
    }
    if (!f && !showTrail) {
        //$('#tabs').height(tabs_height+$('#trial_info_show').height());
        showTrail = true;
    }
    $("#trial_info_show").show();
    $("#orderSave").show();
    containers = new Array();
    var containerTypeSpan = $("#containers li:first span");
    var index = 1;
    $.each(containerTypeSpan, function (i, n) {
        var inputs = $(n).find("input");
        var num = new Number($(inputs[0]).val());
        if (num != 0) {
            var size = $(inputs[1]).val();
            var type = $(inputs[2]).val();
            for (var i = 0; i < num; i++) {
                var container = {
                    id: index, size: size, type: type,
                    index: index
                };
                containers.push(container);
                index++;
            }
        }
    });
    var containersList = new Array();
    $.each(containers, function (i, n) {
        containersList.push(n.id + "号柜-" + n.size + "'" + n.type);
    });
    initCtNumTypeDropdown(containers);
    $("input[id^='gd_ctNumType']").each(function (index, element) {
        var n = (index == 0 ? "" : "_" + index);
        checkedAll($("#selectall_checkbox" + n), false);
    });
    $("#tril_goodsList tr:gt(0)").find("td:eq(9)").each(function (i, n) {
        $(n).text("");
    });
    $("#tril_goodsList tr:gt(0)").find("td:eq(8)").each(function (i, n) {
        $(n).text("");
    });
}

var f = true;
var containerLength = 0;
function addCtTrailType() {
    f = false;
    containerLength = containerLength + 1;
    var ct_size2 = $('input[id=ct_size]').val();
    var ct_type2 = $('input[id=ct_type]').val();
    /*var tabs_height=$('#tabs').height();
     tabs_height += 25;
     $('#tabs').height(tabs_height);*/
    $("#containers li")
        .first()
        .append("<span id='container_" + containerLength
                + "' class='containerType' ><br/><input type='text' class='ct_num' id='ct_num' />&nbsp;<input type='text' class='ct_size' id='ct_size' />&nbsp;<input type='text' class='ct_type' id='ct_type'/></span>");
    $("#containerBtn li").first().append("<span id='deleteType_" + containerLength
                                         + "'><br/><input type='button' class='ui-button ui-widget ui-state-default ui-corner-all' style='cursor:pointer;border-radius:3px' onclick='delCtTrailType("
                                         + containerLength
                                         + ");' id='deleteType' value='删除柜型'/></span>");
    var typeobj = $("#containers li:first span .ct_type:not(.ui-autocomplete-input)")
        .autocomplete({
                          source: ct_type,
                          minLength: 0,
                          open: function (event, ui) {
                              $(this).autocomplete("widget").find("a")
                                  .css("height", "20px");
                          }
                      });
    var sizeobj = $("#containers li:first span .ct_size:not(.ui-autocomplete-input)")
        .autocomplete({source: ct_size, minLength: 0});
    $(typeobj).val(ct_type2);
    $(sizeobj).val(ct_size2);
    initDropdownEven(typeobj);
    initDropdownEven(sizeobj);
    initDropdownStyle(typeobj);
    initDropdownStyle(sizeobj);
    $('input[id=deleteType]').attr('disabled', false);
}

function delCtTrailType(containerLength) {
    if ($("#containers li span").length == 2) {
//		$("#containers li span:last").remove();
//		$("#containers li span:eq("+containerLength+")").remove();
        $("#container_" + containerLength).remove();
        $("#deleteType_" + containerLength).remove();
        $('input[id=deleteType]').attr('disabled', true);
    } else if ($("#containers li span").length > 2) {
//		$("#containers li span:last").remove();
//		$("#containers li span:eq("+containerLength+")").remove();
        $("#container_" + containerLength).remove();
        $("#deleteType_" + containerLength).remove();
        $('input[id=deleteType]').attr('disabled', false);
    } else {
        $('input[id=deleteType]').attr('disabled', false);
    }
    /*var tabs_height=$('#tabs').height();
     tabs_height -= 25;
     $('#tabs').height(tabs_height);*/
}

function zhDateInitialization(obj) {
    $("#" + obj.id).datepicker();
    $("#ui-datepicker-div").css('font-size', '1em');
}

/**
 * 确认货物
 */
var updateData;
function confirmgoodesad() {

    //var ctnumtype = $("#gd_ctNumType").val();
    var ctnumtype = $("#gd_ctNumType_show").text();
    var gd_name = $("#gd_name").val();
    var gd_zhDate = $("#gd_zhDate").val();
    var gd_zhTime = $("#gd_zhTime").val();
    var gd_contacter_company = $("#gd_contacter_company").val();
//	var gd_contacter_address = $("#gd_contacter_address").val();
    var gd_contacter_address_val = $("#gd_contacter_address_val").val();
    var gd_contacter_name = $("#gd_contacter_name").val();
    var gd_contacter_phone = $("#gd_contacter_phone").val();
    var gd_so = $("#gd_so").val();

//	if(gd_so == null || gd_so == ""){
//		jw.confirm('<div><p style="font-style: normal;font-size:
// 16px;color:red;">SO号不能为空,请填写好SO号再确定货物！</p></div>', function () { $(this).dialog('destroy');
// $("#gd_so").focus(); }, function() { $("#gd_so").focus(); }); return false; }else if(gd_name ==
// null || gd_name == "") { jw.confirm('<div><p style="font-style: normal;font-size:
// 16px;color:red;">货物名称不能为空,请填写好货物名称再确定货物！</p></div>', function () { $(this).dialog('destroy');
// $("#gd_name").focus(); }, function() { $("#gd_name").focus(); }); return false; } else
// if(ctnumtype == "" || ctnumtype==null){ jw.confirm('<div><p style="font-style: normal;font-size:
// 16px;color:red;">柜型不能为空,请选择好柜型再确定货物！</p></div>', function () { alert(2);
// $(this).dialog('destroy'); $("#ctnumtype").focus(); }, function() { $("#ctnumtype").focus(); });
// return false; } else if((gd_zhDate == null || gd_zhDate == "") || (gd_zhTime == null ||
// gd_zhTime == "")) { jw.alert('<div><p style="font-style: normal;font-size:
// 16px;color:red;">建议装柜时间不能为空,请填写好建议装柜时间再确定货物！</p></div>'); return false; } else if
// (gd_contacter_company == null || gd_contacter_company == "") { jw.confirm('<div><p
// style="font-style: normal;font-size: 16px;color:red;">装柜工厂名称不能为空,请填写好装柜工厂名称再确定货物！</p></div>',
// function () { $(this).dialog('destroy'); $("#gd_contacter_company").focus(); }, function() {
// $("#gd_contacter_company").focus(); }); return false; } else if(gd_contacter_address_val == null
// || gd_contacter_address_val == "") { jw.confirm('<div><p style="font-style: normal;font-size:
// 16px;color:red;">工厂地址不能为空,请填写好工厂地址再确定货物！</p></div>', function () { $(this).dialog('destroy');
// $("#gd_contacter_address_val").focus(); }, function() { $("#gd_contacter_address_val").focus();
// }); return false; } else if(gd_contacter_name == null || gd_contacter_name == "") {
// jw.confirm('<div><p style="font-style: normal;font-size:
// 16px;color:red;">联系人不能为空,请填写好联系人再确定货物！</p></div>', function () { $(this).dialog('destroy');
// $("#gd_contacter_name").focus(); }, function() { $("#gd_contacter_name").focus(); }); return
// false; } else if(gd_contacter_phone == null || gd_contacter_phone == "") { jw.confirm('<div><p
// style="font-style: normal;font-size: 16px;color:red;">联系电话不能为空,请填写好联系电话再确定货物！</p></div>',
// function () { $(this).dialog('destroy'); $("#gd_contacter_phone").focus(); }, function() {
// $("#gd_contacter_phone").focus(); }); return false; } else { var length = $("#trial_gd_input
// tr").length;
    var _len = $("#trial_gd_input tr").length - 6;
    var table = $("#tril_goodsList");
    var tr;

    //alert($("#trial_gd_input tr").length);
    for (var index = 0; index <= _len; index++) {
        // 如果是修改状态，则清空tr下的子元素，用于添加新元素
        if (updateData) {
            tr = $(updateData);
            tr.empty();
        } else {
            // 否则生成一个新的tr
            /*tr = $("<tr onclick='editgoodesad(this)'>");*/
            tr = $("<tr>");
        }
        var tds = table.find("tr").first().find("td");
        // 处理柜id外的其他字段
        $.each(tds, function (i, n) {
            var value = $("#gd_" + $(n).attr("lang") + (index == 0 ? "" : "_" + index)).val();
//				var trial_gd_tr = $("#trial_gd_input tr:eq("+(index+5)+")");
            if (i == 4) {
                var gd_contacter_city = $(
                    "#gd_contacter_city" + (index == 0 ? "" : "_" + index)).val();
                var gd_contacter_area = $(
                    "#gd_contacter_area" + (index == 0 ? "" : "_" + index)).val();
                var gd_contacter_town = $(
                    "#gd_contacter_town" + (index == 0 ? "" : "_" + index)).val();
                var gd_contacter_address = $(
                    "#gd_" + $(n).attr("lang") + (index == 0 ? "" : "_" + index)).val();
                value =
                    gd_contacter_city + gd_contacter_area + gd_contacter_town
                    + gd_contacter_address;
            }

            if (i == tds.length - 9) {
                var zhsj = "";
//					var gd_zhTime_length = $("#trial_gd_input
// tr:eq("+(index+5)+")").find("td:eq(3)").find("input:eq(1)").val().length;
                var gd_zhTime_length = $(
                    "#gd_zhTime" + (index == 0 ? "" : "_" + index)).val().length;
                if (gd_zhTime_length > 1) {
                    zhsj =
                        $("#gd_zhDate" + (index == 0 ? "" : "_" + index)).val() + " " + $(
                        "#gd_zhTime" + (index == 0 ? "" : "_" + index)).val() + ":00";
//						zhsj = trial_gd_tr.find("td:eq(3)").find("input:eq(0)").val() + " " +
// trial_gd_tr.find("td:eq(3)").find("input:eq(1)").val() + ":00";
                } else if (gd_zhTime_length == 1) {
                    zhsj =
                        $("#gd_zhDate" + (index == 0 ? "" : "_" + index)).val() + " " + "0" + $(
                        "#gd_zhTime" + (index == 0 ? "" : "_" + index)).val() + ":00";
//						zhsj = trial_gd_tr.find("td:eq(3)").find("input:eq(0)").val() + " " + "0"
// + trial_gd_tr.find("td:eq(3)").find("input:eq(1)").val() + ":00";
                } else if (gd_zhTime_length == 0) {
                    zhsj =
                        $("#gd_zhDate" + (index == 0 ? "" : "_" + index)).val() + " " + "00"
                        + ":00";
//						zhsj = trial_gd_tr.find("td:eq(3)").find("input:eq(0)").val() + " " +
// "00" + ":00";
                }
                value = zhsj;
            }
            if (i != tds.length - 5) {
                if (value == undefined || value == null) {
                    value = "";
                }
                // 处理柜id
            } else {
                var ctnumtype = $(tr.find("td")[8]).text();
                var ids = "";
                var ctnumtypes = ctnumtype.split(",");
                $.each(ctnumtypes, function (i, n) {
                    $.each(containers, function (k, m) {
                        if (n.substr(0, n.indexOf("-")) == m.index) {
                            ids += m.id + ",";
                        }
                    });
                });
                if (ids) {
                    ids = ids.substr(0, ids.length - 1);
                }
                value = ids;
            }
            if (i == tds.length - 7) {
//					var ctNumTypeSo = $("#gd_ctNumType" + (index==0?"":"_"+index)).val() + "+" +
// $("#gd_so").val();//20150417注释
                var ctNumTypeSo = $("#gd_ctNumType_show" + (index == 0 ? "" : "_" + index)).text()
                                  + "+" + $("#gd_so").val();//20150417修改
                value = ctNumTypeSo;
            }

            if (i == tds.length - 1) {
                var gd_contacter_address_val = $(
                    "#gd_contacter_address_val" + (index == 0 ? "" : "_" + index)).val();
                value = gd_contacter_address_val;
            }

            if (i == tds.length - 6) {
                tr.append(
                    "<td style='width:200px;' class='custom_bl'><a onclick='editgoodesad($(this).parent().parent()[0])' style='cursor: pointer;color: blue;margin: 10px;'>修改</a>||<a onclick='delgoodes(this)' style='cursor: pointer;color: red;margin: 10px;'>删除</a></td>");
            } else {
                if (value == undefined || value == null || value == "") {
                    if ($(n).attr("lang") && ($(n).attr("lang").indexOf("contacter_company") >= 0
                                              || $(n).attr("lang").indexOf("contacter_address") >= 0
                                              || $(n).attr("lang").indexOf("contacter_name") >= 0
                                              || $(n).attr("lang").indexOf("contacter_phone")
                                                 >= 0)) {
                        value = "";
                    } else {
                        value = $("#gd_" + $(n).attr("lang")).val();
                    }
                }
                var td = $("<td>").text(value);
                if (i == tds.length - 10) {
                    var ctnumtype = $(
                        "#gd_ctNumType_show" + (index == 0 ? "" : "_" + index)).text();
                    value = ctnumtype.split(",").join("<br>");
                    td = $("<td>").html(value);
                }
                if (i == tds.length - 11) {
                    var ctnumtype = $(
                        "#gd_ctNumType_show" + (index == 0 ? "" : "_" + index)).text();
                    value = ctnumtype;
                    td = $("<td>").html(value);
                }
                td.attr("style", $(n).attr("style"));
                td.attr("class", "custom_bl");
                tr.append(td);
            }
        });
        // 如果是修改，则将修改状态标志改成初始状态
        if (updateData) {
            $(updateData).removeClass("ui-state-highlight");
            updateData = null;
        } else {
            // 如果是新增，则添加至表格最后
            table.append(tr);
        }
    }

    var newRow = $("#trial_gd_input tr").length;
    for (var i = newRow; i > 6; i--) {
        deleteTest(i - 6);
    }

    $("#trial_gd_input input:text").each(function (i) {
        this.value = "";
    });
    $("#trial_gd_input input:hidden").each(function (i) {
        if (i != 15) {
            this.value = "";
        }
    });
    //确认货物之后隐藏装运信息表格
    $("#trail_info_shipmen").hide();
    $("#confirmgoodesadBtn").hide();
//		$("#containersInfo").hide();
//		$("#trailContainersInfo").hide();
    countTotalSizeType();
//	}
    $("#orderSave").show();
    $("#tril_goodsList_title").show();
    $("#tril_goodsList").show();
    return true;
}

/**
 * 柜型统计
 */
function countSizeType(obj, index, isCommonTemplate) {
    var sizeType = new Array();
    if (isCommonTemplate == 1) {
        var strTemp = obj.val();
    } else {
        var strTemp = obj.text();
    }
    sizeType = strTemp.split(",");
    //去重
    var tempArray = [];
    var tempObj = {};
    for (var i = 0; i < sizeType.length; i++) {
        if (!tempObj[sizeType[i]]) {
            tempArray.push(sizeType[i]);
            tempObj[sizeType[i]] = 1;
        }
    }
    sizeType = tempArray;
    //计算相同柜的总数
    tempArray = [];
    var str = sizeType.join("-");
    sizeType = [];
    tempArray = str.split("-");
    for (var i = 0; i < tempArray.length; i += 2) {
        sizeType.push(tempArray[i + 1]);
    }
    sizeType.sort();
    var result = "";
    for (var i = 0; i < sizeType.length;) {
        var n = 1;
        var number = 1;
        for (var j = i + 1; j < sizeType.length; j++) {
            if (sizeType[i] == sizeType[j]) {
                number += 1;
                n++;
            }
        }
        result += number + "x" + sizeType[i] + ",";
        i = i + n;
    }
    if (result != "") {
        result = result.substring(0, result.length - 1);
    }
    if (!sizeType || sizeType == "") {
        result = "";
    }
    //$("#gd_ctNumType_show"+index).html(result);
    if (index != "") {
        if (isCommonTemplate == 1) {
            $("#gd_ctNumType_" + index).val(result);
            $("#gd_ctNumType_show_" + index).text(strTemp);
        } else {
            $("#gd_ctNumType" + index).val(result);
        }
    } else {
        if (isCommonTemplate == 1) {
            $("#gd_ctNumType" + index).val(result);
            $("#gd_ctNumType_show" + index).text(strTemp);
        } else {
            $("#gd_ctNumType" + index).val(result);
        }
    }
}

function doGetOneCnInBath(ctn_arr, currIndex) {
    var outputStr = "";
    var badFormatContainer = "";
    var CT_SIZE = "";
    for (var i = 0; i < ctn_arr.length; i++) {
        if (ctn_arr[i] != "") {
            if (ctn_arr[i].split("/").length == 1) {
                if (ctn_arr[i].split("/")[0].length != 11) {
                    badFormatContainer += ctn_arr[i] + ",";
                } else {
                    var containerNo = ctn_arr[i].split("/")[0];
                    if (containerNo && !checkContainerNo(containerNo)) {
                        alert("柜号[" + containerNo + "]输入出错！");
                        return;
                    }
                    $.ajax({
                               type: "GET",
                               async: false,
                               cache: false,
                               url: "declaration-doGetContainerInCTMS?key=" + ctn_arr[i],
                               success: function (data) {
                                   var CT_SIZE = "";
                                   if (data == "[]") {
//							doGetOneCnInBath(ctn_arr, i+1);
                                   } else {
                                       var jdata = eval(data);
                                       if (jdata.length > 1) {
                                           for (x in jdata) {
                                               var rcn = jdata[x].CONTAINER_NO;
                                               CT_SIZE = jdata[x].CT_SIZE;
                                               if (CT_SIZE == "20") {
                                                   CT_SIZE = "S";
                                               } else {
                                                   CT_SIZE = "L";
                                               }
                                               outputStr +=
                                                   "<tr><td><input type='checkbox' value='" + rcn
                                                   + "' title='" + CT_SIZE + "' /></td>";
                                               outputStr += "<td>" + rcn + "</td>";
                                               outputStr += "<td >" + CT_SIZE + "</td></tr>";
                                           }
                                           var arrStr = ctn_arr.toString().replace(/,/g, "|");
                                           outputStr +=
                                               "<tr><td>请为" + ctn_arr[i] + "确定选择一个柜号</td>" +
                                               "<td><a href='javascript:doSelectCNAndGoOn(\""
                                               + arrStr + "\", " + i + ")'>确定选择</a></td>" +
                                               "<td><a href='javascript:doSelectCN(-1)'>取消</a></td>"
                                               +
                                               "</tr>";
                                           $("#cnListSelectTB").append(outputStr);
                                           $("#cnListSelectTB").show();
                                       } else {
                                           for (var x in jdata) {
                                               var rcn = jdata[x].CONTAINER_NO;
                                               CT_SIZE = jdata[x].CT_SIZE;
                                               if (CT_SIZE == "20") {
                                                   CT_SIZE = "S";
                                               } else {
                                                   CT_SIZE = "L";
                                               }
                                               prop_bathOutputStr +=
                                                   "<tr><td><input type='checkbox' value='" + rcn
                                                   + "' title='" + CT_SIZE + "' /></td>";
                                               prop_bathOutputStr += "<td>" + rcn + "</td>";
                                               prop_bathOutputStr +=
                                                   "<td>" + CT_SIZE + "</td></tr>";
                                           }
                                       }
                                   }
                               }
                           });
                }
            } else if (ctn_arr[i].split("/").length == 2) {
                var rcn = ctn_arr[i].split("/")[0];
                CT_SIZE = ctn_arr[i].split("/")[1];
                if (rcn && !checkContainerNo(rcn)) {
                    alert("柜号[" + rcn + "]输入出错！");
                    return;
                }
                if (CT_SIZE && !checkContainerSize(CT_SIZE)) {
                    alert("柜号[" + rcn + "]输入柜型[" + CT_SIZE + "]出错！");
                    return;
                }
                if (rcn.length != 11) {
                    badFormatContainer += ctn_arr[i] + ",";
                } else {
                    if (CT_SIZE == "20") {
                        CT_SIZE = "S";
                    } else if (CT_SIZE == "40" || CT_SIZE == "45") {
                        CT_SIZE = "L";
                    } else {
                        badFormatContainer += ctn_arr[i] + ",";
                    }
                    prop_bathOutputStr +=
                        "<tr><td><input type='checkbox' value='" + rcn + "' title='" + CT_SIZE
                        + "' /></td>";
                    prop_bathOutputStr += "<td>" + rcn + "</td>";
                    prop_bathOutputStr += "<td >" + CT_SIZE + "</td></tr>";
                }
            } else {
                badFormatContainer += ctn_arr[i] + ",";
            }
        }
    }
    if (badFormatContainer != "") {
        prop_bathOutputStr = "";
        outputStr = "";
        alert(badFormatContainer.substr(0, badFormatContainer.length - 1) + "柜号格式不正确!");
        return;
    } else {
        var regex1 = /<tr>/gi;
        var arrMatches = prop_bathOutputStr.match(regex1);
        jlength = arrMatches.length;
        prop_bathOutputStr += "<tr><td>共" + jlength + "只柜</td>" +
                              "<td><a href='javascript:doSelectCN(0)'>确定</a></td>" +
                              "<td><a href='javascript:doSelectCN(-1)'>取消</a></td>" +
                              "</tr>";
        var sumStr = "共" + jlength + "只柜";
        $("#label_selectAllCN")[0].innerText = sumStr;
        $("#cnListSelectTB").append(prop_bathOutputStr);
        $("#cnListSelectTB").show();
    }
}
